import java.util.ArrayList;
import java.util.List;

/**
 * @author LKQ
 * @date 2022/1/20 15:58
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.partitionLabels("ababcbacadefegdehijhklij");
    }
    public List<Integer> partitionLabels(String s) {
        int[] cnt = new int[26];
        for (int i = 0; i < s.length(); i++) {
            // 记录每个字符最后一次出现的位置
            cnt[s.charAt(i)- 'a'] = i;
        }
        List<Integer> ans = new ArrayList<>();
        int start = 0, end = 0;
        for (int i = 0; i < s.length(); i++) {
            end = Math.max(end, cnt[s.charAt(i)-'a']);
            if (i == end) {
                ans.add(end - start + 1);
                start = end + 1;
            }
        }
        return ans;
    }
}
